/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-11-26
*/
package com.rzico.account.controller;

import com.rzico.account.entity.Foundation;
import com.rzico.account.service.FoundationService;
import com.rzico.annotation.Log;
import com.rzico.base.BaseController;
import com.rzico.base.CommResult;
import com.rzico.basics.entity.Enterprise;
import com.rzico.basics.service.EnterpriseService;
import com.rzico.entity.Pageable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 基金管理控制层
 *
 * @author Rzico Boot
 * @version 1.0
 * @date 2020-11-26
 */
@Api(description = "基金管理接口")
@RestController
@RequestMapping("/foundation")
public class FoundationController extends BaseController {

    @Autowired
    private FoundationService foundationService;

    @Autowired
    private EnterpriseService enterpriseService;


    /**
     * 查询基金管理
     *
     * @return
    */
    @ApiOperation("查询基金管理")
    @GetMapping("/getInfo")
    @ApiImplicitParams({@ApiImplicitParam(name = "mchId", value = "商户ID", dataType = "String", paramType = "query")
    })
    public CommResult<Foundation> getInfo(String mchId, Pageable pageable) {

        Map<String, Object> params = new HashMap<String, Object>();
        Enterprise enterprise = enterpriseService.findByMch(mchId);
        if (enterprise!=null) {
            params.put("enterpriseId", enterprise.getId());
        } else {
            return CommResult.error("没有开通企业");
        }

        Foundation foundation = null;
        List<Foundation> list = foundationService.selectList(params);
        if (list.size()>0) {
            foundation = list.get(0);
        } else {
            foundation.setEnterpriseId(enterprise.getId());
            foundation.setAtvy(BigDecimal.ZERO);
            foundation.setAtvyRate(BigDecimal.ZERO);
            foundation.setBonus(BigDecimal.ZERO);
            foundation.setBonusRate(BigDecimal.ZERO);
            foundation.setFund(BigDecimal.ZERO);
            foundation.setFundRate(BigDecimal.ZERO);
            foundation.setVip1(BigDecimal.ZERO);
            foundation.setVip2(BigDecimal.ZERO);
            foundation.setVip3(BigDecimal.ZERO);
            foundation.setVip4(BigDecimal.ZERO);
            foundation.setVip5(BigDecimal.ZERO);
            foundation.setCreateDate(new Date());
        }
        return CommResult.success(foundation);

    }

}
